package Threads.ThreadPool.java_threadpool;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class Execption_test {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(2);

        //并不会报错
        executorService.submit(()->{
            System.out.println("ahahha");
            int a=1/0;
        });

        //处理办法1：主动try catch
       /* executorService.submit(()->{
            try{
                int a=1/0;
            }catch (Exception e){
                e.printStackTrace();
            }
        });*/

        //处理办法2：使用future对象
        Future<Boolean> f = executorService.submit(() -> {
            int i = 1 / 0;
            return true;
        });
        System.out.println(f.get());
        executorService.shutdown();
    }
}
